package com.twu.biblioteca.Login;

import com.twu.biblioteca.BibliotecaApp;
import com.twu.biblioteca.IView;
import com.twu.biblioteca.Menu.MenuView;
import com.twu.biblioteca.Users.UserList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * User: DK
 * Date: 9/25/13
 * Time: 1:54 AM
 * To change this template use File | Settings | File Templates.
 */
public class LoginView implements IView {

    private UserList userList = new UserList();

    @Override
    public String display() {
        return "Please enter the following details:\n";

    }

    @Override
    public IView interact() {
        System.out.print("Username: ");

        String username;
        Scanner usernameScanner = new Scanner(System.in);
        username = usernameScanner.nextLine();

        System.out.print("Password: ");

        String password;
        Scanner passwordScanner = new Scanner(System.in);
        password = passwordScanner.nextLine();

        if(BibliotecaApp.user.login(username,password))
        {
            System.out.println("Welcome! Login Successful");
            BibliotecaApp.user = UserList.returnSelectedUser(username,password);
        }
        else
        {
            System.out.println("Sorry Invalid Username Or Password");
        }

        return new MenuView();
    }
}
